package com.eight.group.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.eight.group.entity.QueryPageBean;
import com.eight.group.entity.Result;
import com.eight.group.mapper.MemberuploadMapper;
import com.xqx.eight.group.service.MemberruploadService;
import org.apache.zookeeper.data.Id;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class MemberuploadServiceimpl implements MemberruploadService {
    @Autowired
    private MemberuploadMapper mapper;

    @Override
    public List<Map<String, Object>> findAll(QueryPageBean bean) {
        String str = bean.getQueryString() == null || bean.getQueryString() == "" ? null : "%" + bean.getQueryString() + "%";
        List<Map<String, Object>> mapList = mapper.findAll(str);
        return mapList;
    }

    /**
     * 添加
     *
     * @param map
     */
    @Override
    public Result add(Map<String, Object> map) {
        String id = mapper.findNameandfileNo(map);
        if (id != null) {
            Object fileName = map.get("filename");
            if (fileName != null) {
                map.put("statusofreporting", "已上传");
            } else {
                map.put("statusofreporting", "未上传");
            }
            map.put("id", Integer.parseInt(id));
            mapper.add(map);
            return new Result(true, "添加成功!");
        }
        return new Result(false, "添加失败!没有会员名或档案号");
    }

    @Override
    public List<Map<String, Object>> findStmeal() {
        List<Map<String, Object>> stmeals = mapper.findStmeal();
        return stmeals;
    }

    //删除
    @Override
    public void delete(int id) {
        mapper.delete(id);
    }

    @Override
    public void edit(Map<String, Object> map) {
        String id = mapper.findNameandfileNo(map);
        if (id != null) {
            Object fileName = map.get("filename");
            if (fileName != null) {
                map.put("statusofreporting", "已上传");
            } else {
                map.put("statusofreporting", "未上传");
            }
            map.put("mid", Integer.parseInt(id));
            //   mapper.add(map);
            mapper.edit(map);
        }
    }
}
